//
//  WYCHomeCell.m
//  初试
//
//  Created by 中企互联 on 2017/10/11.
//  Copyright © 2017年 李胜军. All rights reserved.
//

#import "WYCHomeCell.h"

@interface WYCHomeCell ()

/** 是否认证*/
@property (nonatomic,strong)UILabel * typelabel;

@end
@implementation WYCHomeCell

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    WYCHomeCell * cell = [tableView dequeueReusableCellWithIdentifier:[WYCHomeCell ID]];
    cell = [[WYCHomeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[WYCHomeCell ID]];
    cell.backgroundColor = WYCGlobalBg;
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setMember];
        
    }
    return self;
}
//cell控件摆放
- (void)setMember{
    
    /** 判断还款类型*/
    
    
}

- (void)setBillmodelFrame:(WYCBillFrameModel *)billmodelFrame{
    _billmodelFrame = billmodelFrame;
    
    WYCBillModel * Billmodel = billmodelFrame.Billmodel;
    NSInteger bankid = [billmodelFrame.Billmodel.bankId integerValue];
    switch (bankid) {
        case 10000://招商银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_zhaoshang"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_zhaoshang"];
            break;
        case 10001://工商银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_gs"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_gs"];

            break;
        case 10002://农业银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_ny"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_ny"];

            break;
        case 10003://  建设银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_jianshe"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_js"];

            break;
        case 10004://中国银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_zhongguo"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_zg"];

            break;
        case 10005:  //浦发银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_pufa"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_pufa"];

            break;
        case 10006:  //交通银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_jiaotong"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_jiaotong"];

            break;
        case 10007:  //民生银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_minsheng"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_ms"];

            break;
        case 10009:  //广东发展银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_gf"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_gf"];

            break;
        case 10010:  //中信银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_zhongxin"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_zx"];

            break;
        case 10011:  //  华夏银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_hx"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_hx"];

            break;
        case 10012:  //  兴业银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_xingye"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_xingye"];

            break;
        case 10014:  //  江苏银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_jiangsu"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_js"];

            break;
        case 10016:  //  北京银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_bj"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_bj"];

            break;
        case 10020://10020  光大银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_gd"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_gd"];

            break;
        case  10024://平安银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_pinan"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_pinan"];

            break;
        case 10027:  //上海银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_shanghai"];
            _bankImage.image = [UIImage imageNamed:@"bank_circle_sh"];

            break;
        case  10028://  中国邮政储蓄银行
            _bankbgImage.image = [UIImage imageNamed:@"bank_bg_youzheng"];
            _bankImage.image = [UIImage imageNamed:@"bank_icon_yz"];

            break;
        
        default:
            _bankbgImage.image = [UIImage imageNamed:@"icon_other_bank"];
            _bankImage.image = [UIImage imageNamed:@"bank_icon_gs"];

            break;
    }
    //尾号
    NSString * lastNumberStr = [NSString stringWithFormat:@"%@",Billmodel.lastNumber];
//    _numberLb.text = lastNumberStr;
    //银行名称
    NSString  *bankNm = [NSString stringWithFormat:@"%@",Billmodel.bankName];
//   _bankLb.text =  [bankNm substringToIndex:4];
    _bankLb.text =  [NSString  stringWithFormat:@"%@(%@)",bankNm,lastNumberStr];
    _bankLb.textColor = [UIColor blackColor];
    
    //姓名
    NSString *strname = Billmodel.name;
    NSString *strnm =[NSString stringWithFormat:@"%@",strname];
    NSString *strn =  [strnm substringToIndex:1];

    
//    NSString *newStr = [strname stringByReplacingOccurrencesOfString:strn withString:@"*"];
    _namelb.text = strname;
    
   
    
    //账单日
    NSString*string1 = Billmodel.billDate;
    //月
    string1 = [string1 substringToIndex:2];

    NSString  *dayStr1 =  [Billmodel.billDate substringFromIndex:3];//截取掉下标2之前的字符串
    //日
    int  day = [[dayStr1 substringToIndex:2] intValue];
    NSString *result1 = [NSString stringWithFormat:@"%d/%d",[string1 intValue] ,day];
    
    //还款日
    NSString*string = Billmodel.dueDate;
    string = [string substringToIndex:2];
  
    NSString  *dayStr =  [Billmodel.dueDate substringFromIndex:3];//截取掉下标2之前的字符串
    int  day1 = [[dayStr substringToIndex:2] intValue];

    NSString *result = [NSString stringWithFormat:@"%d/%d",  [string intValue],day1];

    //总额度
    _totalLb.text = Billmodel.creditLine;
   _banklabel.text = Billmodel.dueDate;
   _staylabel.text = Billmodel.billDate;
    // 获取代表公历的NSCalendar对象
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    // 获取当前日期
    NSDate* dt = [NSDate date];
    // 定义一个时间字段的旗标，指定将会获取指定年、月、日、时、分、秒的信息
    unsigned unitFlags = NSCalendarUnitYear |
    NSCalendarUnitMonth |  NSCalendarUnitDay |
    NSCalendarUnitHour |  NSCalendarUnitMinute |
    NSCalendarUnitSecond | NSCalendarUnitWeekday;
    // 获取不同时间字段的信息
    NSDateComponents* comp = [gregorian components: unitFlags
                                          fromDate:dt];
    // 获取各时间字段的数值
    NSLog(@"现在是%ld月 " , comp.month);
    NSLog(@"现在是%ld日" , comp.day);
    
   
    

    if (comp.month == [string1 intValue]) {
        if (comp.day == day||comp.day>day) {
             double a = [Billmodel.billAmount doubleValue];
            _moneyLb.text = [NSString stringWithFormat:@"%.1f",a];
            CGSize size = CGSizeMake(20,20); //设置一个行高上限
            NSDictionary *attribute = @{NSFontAttributeName: _moneyLb.font};
            CGSize labelsize = [_moneyLb.text boundingRectWithSize:size options:NSStringDrawingUsesDeviceMetrics attributes:attribute context:nil].size;
            _moneyLb.frame = CGRectMake(30, 80, labelsize.width + 13, labelsize.height);
            _moneyLb.textAlignment = NSTextAlignmentLeft;
            _moneyLb.textColor = wycMain;

            _moneyPlanlb.frame = CGRectMake(_moneyLb.frame.size.width+_moneyLb.frame.origin.x, 80, 120, 30);
            _moneyPlanlb.text = @"本期账单";
            _moneyPlanlb.textColor = [UIColor grayColor];
        }
        else{
            _moneyLb.text = [NSString stringWithFormat:@"%@",Billmodel.outbBllDay];
            CGSize size = CGSizeMake(20,20); //设置一个行高上限
            NSDictionary *attribute = @{NSFontAttributeName: _moneyLb.font};
            CGSize labelsize = [_moneyLb.text boundingRectWithSize:size options:NSStringDrawingUsesDeviceMetrics attributes:attribute context:nil].size;
            _moneyLb.frame = CGRectMake(30, 80, labelsize.width + 20, labelsize.height);
            _moneyLb.textAlignment = NSTextAlignmentLeft;
            _moneyPlanlb.frame = CGRectMake(_moneyLb.frame.size.width+_moneyLb.frame.origin.x, 80, 120, 30);
            _moneyLb.textColor = wycMain;
            _moneyPlanlb.textColor = [UIColor grayColor];

            _moneyPlanlb.text = @"天后出账单";

            
        }
    }
    else{
        _moneyLb.text = [NSString stringWithFormat:@"%@",Billmodel.outbBllDay];
        CGSize size = CGSizeMake(20,20); //设置一个行高上限
        NSDictionary *attribute = @{NSFontAttributeName: _moneyLb.font};
        CGSize labelsize = [_moneyLb.text boundingRectWithSize:size options:NSStringDrawingUsesDeviceMetrics attributes:attribute context:nil].size;
        _moneyLb.frame = CGRectMake(30, 80, labelsize.width + 20, labelsize.height);
        _moneyLb.textAlignment = NSTextAlignmentLeft;
        _moneyLb.textColor = wycMain;
        _moneyPlanlb.frame = CGRectMake(_moneyLb.frame.size.width+_moneyLb.frame.origin.x, 80, 120, 30);
        
        _moneyPlanlb.text = @"天后出账单";
        _moneyPlanlb.textColor = [UIColor grayColor];

        
    }
    //是否认证
    self.typelabel.frame = billmodelFrame.approveF;
    if ([Billmodel.approve isEqualToString:@"2"]) {
            // 立即还款
            self.repaymentButton = [[UIButton alloc] init];
            self.repaymentButton.frame = CGRectMake(ScreenWidth-90, 65, 80, 30);
            [self.repaymentButton setTitle:@"立即认证" forState:UIControlStateNormal];
            [self.repaymentButton.layer setBorderWidth:1.0];
            self.repaymentButton.layer.cornerRadius = 10;
            self.repaymentButton.layer.masksToBounds = YES;
            self.repaymentButton.layer.borderWidth = 1;
        self.repaymentButton.layer.borderColor = WYCMain.CGColor;
            self.repaymentButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
            [self.repaymentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self addSubview:self.repaymentButton];
        
    }else{
        NSLog(@"还款状态%@",Billmodel.state);
        
       
        
        if ([Billmodel.userCard isEqualToString:@"0"]) {
            NSString * aooroveStr = [NSString stringWithFormat:@"他人卡"];
            self.typelabel.text = aooroveStr;
            self.typelabel.backgroundColor = [UIColor orangeColor];
        }else{
            
            self.typelabel = [[UILabel alloc] init];
            self.typelabel.frame = CGRectMake(ScreenWidth-90, 65, 60, 20);
            self.typelabel.textColor = [UIColor whiteColor];
            self.typelabel.layer.masksToBounds = YES;

            self.typelabel.textAlignment = NSTextAlignmentCenter;
            self.typelabel.layer.cornerRadius = 10;
            self.typelabel.font = [UIFont systemFontOfSize:SmallFont];
            [self addSubview:self.typelabel];
            if ([Billmodel.state isEqualToString:@"0"]){
                
                self.typelabel.text = @"";
            } else if ([Billmodel.state isEqualToString:@"1"]){
                NSString * aooroveStr = [NSString stringWithFormat:@"待还款"];
                self.typelabel.text = aooroveStr;
                self.typelabel.backgroundColor = WYCMain;
            }else if ([Billmodel.state isEqualToString:@"2"]){
                NSString * aooroveStr = [NSString stringWithFormat:@"已还清"];
                self.typelabel.text = aooroveStr;
                self.typelabel.backgroundColor = [UIColor greenColor];
            }else if ([Billmodel.state isEqualToString:@"3"]){
                NSString * aooroveStr = [NSString stringWithFormat:@"待还款"];
                self.typelabel.text = aooroveStr;
                self.typelabel.backgroundColor =WYCMain;
            }else{
                NSString * aooroveStr = [NSString stringWithFormat:@"待还款"];
                self.typelabel.text = aooroveStr;
                self.typelabel.backgroundColor = WYCMain;

            }
        }
        
    }
    
}
- (void)repayMentClick{
    
    WYCLogFunc;
}
+(NSString *)ID{
    return @"cell";
}

@end
